const data = {
  isImport: false,
}

const mutations = {
  /**
   * 设置system
   */
  SET_SYSTEM(state, system) {
    // 如果system有值，那么就用system中的值
    // 否则就取原来的state的值
    state.isImport = system.isImport ?? state.isImport
  },
}

const actions = {
  async initializeSystem({ commit }) {
    // Fetch data from Chrome storage API
    chrome.storage.local.get(['system'], result => {
      const system = { isImport: false, ...result.system }

      // Commit the "SET_FOLDERS" mutation with the result
      commit('SET_SYSTEM', system)
    })
  },
  resetAndClear({ state, commit }) {
    commit('SET_SYSTEM', { isImport: false })

    // 将更新后的值再保存到chrome.storage.local
    chrome.storage.local.set({ system: state })
  },
  setIsImport({ state, commit }) {
    commit('SET_SYSTEM', { isImport: true })

    // 将更新后的值再保存到chrome.storage.local
    chrome.storage.local.set({ system: state })
  },
}

export default {
  namespaced: true,
  state: data,
  mutations,
  actions,
}
